package Test.StirngTest;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @className: OperateServerMap
 * @description:
 * @author: lyjunpm
 * @date: 2022/11/9 10:16
 **/
public class xxxMap {
    private static Map<String,String> map = new LinkedHashMap<String,String>();
    static {
//        map.put("101","save,insert,add");
//        map.put("102","delete");
//        map.put("103","query,get,select");
//        map.put("104","update,modify");
//        map.put("105","login");
//        map.put("106","logout");
//        map.put("107","copy,backup");
//        map.put("108","revert");
//        map.put("109","import");
//        map.put("110","export");
//        map.put("111","download");
//        map.put("112","upload");
//        map.put("113","warning");
//        map.put("114","vires");
//        map.put("115","view,.jsp");
//        map.put("201","system");
//        map.put("202","business");
//        map.put("301","high");
//        map.put("302","middle");
//        map.put("303","low");
    }

    public static void main(String[] args) {
        System.out.println(map.get("a"));
        Integer num = 1;
        for (int i = 1; i <= num; i++) {
            System.out.println(i);
        }
//        Set<String> strings = map.keySet();
//        Set<Map.Entry<String, String>> entries = map.entrySet();
//        List<String> values = map.values().stream().distinct().collect(Collectors.toList());

//        System.out.println(strings);
//        System.out.println(entries);
//        System.out.println(values);

    }

    //通过value获取key
    public static String vaildParams(String paramValue){
        return map.entrySet().stream()
                .collect(Collectors.toMap(entity-> entity.getValue(), entity-> entity.getKey()))
                .get(paramValue);
    }

    //通过value模糊匹配获取key 此方法目前仅适用于这种已知key、value且数据量较少
    //因为此方法会遍历所有值 无法中断 所以性能等方面需要考虑
    public static String parseMapForValue(String paramValue) {
        if (paramValue == null || paramValue.length() <= 0) {
            return null;
        } else {
            return map.entrySet().stream()
                    .filter((e) -> checkValue(e.getValue(),paramValue))
                    .collect(Collectors.toMap(
                            (e) -> paramValue,
                            (e) -> e.getKey()
                    )).get(paramValue);
        }
    }

    //字符串匹配
    private static boolean checkValue(String value,String paramValue) {
        String[] split = value.split(",");
        for(String str:split){
            System.out.println(str);
            if (paramValue.indexOf(str)>-1){
                return true;
            }
        }
        return false;
    }
}
